<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>产品列表</title>

    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>
    <link href="../../resource/css/font-awesome.min.css?v=4.4.0" rel="stylesheet"
          th:href="@{/resource/css/font-awesome.min.css?v=4.4.0}"/>
    <!-- Morris -->
    <link href="http://cdn.viptool.cn/lib/morris.js/0.4.3/morris.css" rel="stylesheet">
    <link href="../../resource/css/animate.min.css" rel="stylesheet" th:href="@{/resource/css/animate.min.css}"/>
    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>
    <link href="../../resource/hotui/js/plugins/datetimepick/css/daterangepicker.css"
          th:href="@{/resource/hotui/js/plugins/datetimepick/css/daterangepicker.css}" rel="stylesheet"/>
    <link href="../../resource/lib/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css" type="text/css"
          th:href="@{/resource/lib/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css}" rel="stylesheet"/>

    <style type="text/css">
        .city-picker-selector select {

        }

        .daterangepicker {
            z-index: 999999999 !important;
        }

        .nav-tabs input {
            width: 20px;
            height: 23px;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight tooltip-demo">
    <!--search-->
    <form role="form" id="searchForm" class="search-panel" method="get" th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <input type="hidden" th:value="${pageIndex}" name="pageIndex"/>
                            <input type="hidden" th:value="*{saleType}" name="saleType" id="saleType"/>
                            <div class="form-group m-r-sm">
                                <label class=" control-label" for="keyword">商品名称：</label>
                                <input type="text" class="form-control input-sm mb10" id="keyword"
                                       name="keyword" th:value="${condition.keyword}" placeholder="商品名称"
                                       style="width: 156px;"/>
                            </div>
                            <div class="form-group m-r-sm" sec:authorize="hasRole('ADMIN')">
                                <label class=" control-label" for="keyword">所属店铺：</label>
                                <input class="form-control input-sm mb10" id="shopTitle" name="shopTitle"
                                       placeholder="店铺名称" style="width: 156px;" th:value="${condition.shopTitle}"
                                       type="text"/>
                            </div>
                            <div class="form-group m-r-sm">
                                <button type="button"
                                        onclick="pageHandler.search(1)"
                                        class="btn btn-primary btn-sm m-b-none">搜索
                                </button>
                                <button type="button" onclick="pageHandler.searchAll()"
                                        class="btn btn-primary btn-sm m-b-none">显示全部
                                </button>
                            </div>
                            <a sec:authorize="hasRole('MERCHANT')" href="javascript:pageHandler.add()"><span
                                    class="btn btn-info btn-sm"
                                    style="float: right;">添加</span></a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->

    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container">
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body table-responsive">


                                <table class="table table-bordered table-hover table-center report-table">
                                    <thead>
                                    <tr>
                                        <th>商品ID</th>
                                        <th>商品名称</th>
                                        <th>所属类目</th>
                                        <th sec:authorize="hasRole('ADMIN')">店铺名称</th>
                                        <th>状态</th>
                                        <th>库存</th>
                                        <th>售价</th>
                                        <th>添加时间</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    <!--/*@thymesVar id="row" type="com.treasure.mall.biz.entity.product.ProductPO"*/-->
                                    <tr th:each="row,index:${productList}">
                                        <td th:text="${row.productId}"></td>
                                        <td th:text="${row.productName}"></td>
                                        <td>
                                            <span th:if="${row.category!=null}"
                                                  th:text="${row.category.catName}"></span>
                                        </td>
                                        <td sec:authorize="hasRole('ADMIN')">
                                            <span th:if="${row.merchantPO!=null}"
                                                  th:text="${row.merchantPO.data.title}"></span>
                                        </td>
                                        <td th:switch="${row.statusCode}">
                                            <span th:case="0" class="danger">下架</span>
                                            <span th:case="1" class="color-success">上架</span>
                                        </td>
                                        <td>
                                            <span th:text="${row.store}">12</span>
                                            <br>
                                            <span class="color-danger">（锁定：<span
                                                    th:text="${row.freeze}">12</span>）</span>
                                        </td>
                                        <td th:text="${row.price}">1211</td>
                                        <td th:text="${#temporals.format(row.createTime,'yyyy-MM-dd HH:mm:ss')}"></td>
                                        <td>

                                            <th:block
                                                    th:if="${row.auctionStatus.code!=2}">

                                                <button class="btn btn-white btn-xs m-b-none"
                                                        onclick="pageHandler.edit('123')"
                                                        th:onclick="|pageHandler.edit('${row.productId}')|"
                                                        type="button">编辑
                                                </button>
                                            </th:block>
                                            <button th:if="${row.saleType.code==1}"
                                                    onclick="pageHandler.auctionModalShow('123')"
                                                    th:onclick="|pageHandler.auctionModalShow('${row.productId}','${row.auctionStatus.code}')|"
                                                    type="button"
                                                    class="btn btn-white btn-xs m-b-none">拍卖设置
                                            </button>
                                            <button th:if="${row.saleType.code==1}"
                                                    onclick="pageHandler.bidList(123)"
                                                    th:onclick="|pageHandler.bidList(${row.productId})|"
                                                    type="button"
                                                    class="btn btn-white btn-xs m-b-none">出价记录
                                            </button>
                                            <button sec:authorize="hasRole('ADMIN')" onclick="pageHandler.toArea(1)"
                                                    th:onclick="|pageHandler.toArea(${row.productId})|"
                                                    type="button"
                                                    class="btn btn-xs m-b-none btn-primary">添加到专区
                                            </button>

                                            <th:block
                                                    th:if="${row.saleType.code==0||row.auctionStatus.code==2}">
                                                <button onclick="pageHandler.del('123')"
                                                        th:onclick="|pageHandler.del('${row.productId}')|"
                                                        type="button"
                                                        class="btn btn-xs m-b-none btn-warning">删除
                                                </button>
                                            </th:block>

                                        </td>
                                    </tr>
                                    </tbody>
                                </table>

                                <p style="float: left; margin: 20px 0;">
                                    共<span th:text="${totalRecords}"></span>条记录，当前第<span th:text="${pageIndex}"></span>/<span
                                        th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                </p>
                                <ul style="float: right;" class="pagination pagination-split">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="sel_area_modal">
    <div class="form-horizontal" style="width: 400px;">
        <input type="hidden" id="area_productId"/>
        <th:block th:each="area:${areas}">
            <div class="form-group form-inline">
                <div class="col-sm-7">
                    <p class="form-control-static" th:text="${area.title}">好物推荐</p>
                </div>
                <div class="col-sm-5">
                    <input class="form-control m-l" th:value="${area.id}" name="area_chk" type="checkbox"/>
                </div>
            </div>
            <div class="hr-line-dashed "></div>
        </th:block>
    </div>
</script>

<script type="text/html" id="auction_modal">
    <input type="hidden" id="auction_id"/>
    <input type="hidden" id="action_productId"/>
    <div class="form-horizontal" style="width: 600px;">
        <div class="form-group">
            <label class="col-sm-2 control-label">开始时间:</label>

            <div class="col-sm-10">
                <div style="width: 200px" class='input-group date'>
                    <input readonly type="text" class="form-control input-sm m-b-none" id="auction_startTime"
                           placeholder="预告时间"/>
                    <span class="input-group-addon">
                        <span class="glyphicon glyphicon-calendar"></span>
                    </span>
                </div>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">拍卖时长:</label>

            <div class="col-sm-10 form-inline">
                <div class="input-group">
                    <div class="input-group m-b">
                        <input type="text" id="auction_duration" class="form-control input-s-sm only-num"
                               placeholder="拍卖时常"> <span class="input-group-addon">分</span>
                    </div>
                </div>
                <p class="form-control-static">结束时间：<span id="auction_endTime"></span></p>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">起拍价:</label>
            <div class="col-sm-4">
                <div class="input-group">
                    <span class="input-group-addon">¥</span>
                    <input name="price" id="auction_startingPrice" type="text"
                           class="form-control input-s-sm only-float" placeholder="起拍价">
                </div>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">加价幅度:</label>
            <div class="col-sm-4">
                <div class="input-group">
                    <span class="input-group-addon">¥</span>
                    <input name="price" id="auction_unitIncrease" type="text"
                           class="form-control input-s-sm only-float" placeholder="加价幅度">
                </div>
            </div>
        </div>
        <div class="hr-line-dashed "></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">是否延时:</label>
            <div class="col-sm-10">
                <select style="width: 100px;" class="form-control input-sm mb10" id="auction_delay"
                        name="auction_delay">
                    <option value="0">否</option>
                    <option value="1">是</option>
                </select>
                <p class="form-control-static color-danger">
                    否：倒计时结束即截拍<br/>
                    是：倒计时结束10秒内如果有新的出价会延长截拍时间，每次延长10秒，系统最多只延长3次
                </p>
            </div>
        </div>
        <div class="hr-line-dashed " style="display: none"></div>
        <div class="form-group" style="display: none">
            <label class="col-sm-2 control-label">保证金:</label>
            <div class="col-sm-4">
                <div class="input-group">
                    <span class="input-group-addon">¥</span>
                    <input name="price" id="auction_securityDeposit" value="0" type="text"
                           class="form-control input-s-sm only-float" placeholder="保证金">
                </div>
            </div>
        </div>
    </div>
</script>

<!--基础框架js-->
<script src="../../resource/js/jquery.min.js?v=2.1.4" th:src="@{/resource/js/jquery.min.js?v=2.1.4}"></script>
<script src="../../resource/js/bootstrap.min.js?v=3.3.5" th:src="@{/resource/js/bootstrap.min.js?v=3.3.5}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20200720?1234567"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js?20200720}"></script>
<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>

<script src="../../resource/lib/moment.min.js" th:src="@{/resource/lib/moment.min.js}"></script>
<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>
<script src="../../resource/lib/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"
        th:src="@{/resource/lib/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js}"></script>


<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  0;
    const pageUri = /*[[@{/product/normalList}]]*/  "";
    const detailUri = /*[[@{/product/detail}]]*/  "";
    const toAreaUri = /*[[@{/specialArea/products/add}]]*/  "";
    const editUri = /*[[@{/product/normalEdit}]]*/  "";
    const auctionUri = /*[[@{/auction}]]*/  "";
</script>

<script>
    var auctionModal = $("#auction_modal").modal("拍卖设置", function () {
        let productId = $("#action_productId").val();
        let startTime = $("#auction_startTime").val();
        // let preEndTime = $("#auction_endTime").val();
        let duration = $("#auction_duration").val();
        let startingPrice = $("#auction_startingPrice").val();
        let unitIncrease = $("#auction_unitIncrease").val();
        let securityDeposit = $("#auction_securityDeposit").val();
        let delay = $("#auction_delay").val();

        let requestData = {
            id: $("#auction_id").val(),
            productId: productId,
            startTime: startTime,
            duration: duration,
            // preEndTime: preEndTime,
            startingPrice: startingPrice,
            unitIncrease: unitIncrease,
            securityDeposit: securityDeposit,
            delay: delay
        };

        hot.ajax(auctionUri + "/edit", requestData, function (apiResult) {
            if (apiResult.resultCode === 2000) {
                hot.tip.success("设置成功", function () {
                    window.location.reload();
                });
            } else {
                hot.tip.error(apiResult.resultMsg);
            }
        }, function () {
        }, "post", 300);
    });

    var selAreaModal = $("#sel_area_modal").modal("选择专场", function () {
        let areaId = "";

        $("input[name=area_chk]:checked").each(function () {
            areaId += $(this).val() + ",";
        });
        areaId = areaId.substr(0, areaId.length - 1);

        hot.ajax(toAreaUri, {
            areaId: areaId,
            productId: $("#area_productId").val()
        }, function (apiResult) {
            if (apiResult.resultCode === 2000) {
                hot.tip.success("添加成功");
                selAreaModal.hide();
            } else {
                hot.tip.error(apiResult.resultMsg);
            }
        }, function () {
        }, "post")
    });
    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            pageHandler.search(p);
        });
        $(document).keyup(function (event) {
            if (event.keyCode === 13) {
                $(".searchBtn").trigger("click");
            }
        });
    });

    $(function () {
        pageHandler.init();
    });
    var pageHandler = {
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri;
        },
        init: function () {
        },
        add: function () {
            let uri = editUri + '?saleType=' + $("#saleType").val() + '&productId=0';
            hot.newTab(uri, "添加商品");
        },
        edit: function (id) {
            let uri = editUri + '?saleType=' + $("#saleType").val() + '&productId=' + id;
            hot.newTab(uri, "编辑商品");
        },
        toArea: function (id) {
            selAreaModal.show(function () {
                $("#area_productId").val(id);
            })
        },
        bidList: function (productId) {
            let uri = auctionUri + "/bidList?productId=" + productId;
            hot.iframeModal(uri, '400px', '600px', "出价记录");
        },
        auctionModalShow: function (productId, code) {
            let options = {
                btn: ["确定", "关闭"]
            };
            if (code === 2) {
                options.btn = [];
            }
            auctionModal.show(function () {
                $("#auction_startTime").datetimepicker({
                    autoclose: true,
                    format: 'yyyy-mm-dd hh:ii:ss',
                    minuteStep: 1
                });
                $("#auction_endTime").datetimepicker({
                    autoclose: true,
                    format: 'yyyy-mm-dd hh:ii:ss',
                    minuteStep: 1
                });
                $("#action_productId").val(productId);
                hot.ajax(auctionUri + "/currentSession", {
                    productId: productId
                }, function (apiResult) {
                    $("#auction_startTime").val(apiResult.data.startTime);
                    $("#auction_endTime").val(apiResult.data.endTime);
                    $("#auction_duration").val(apiResult.data.duration);
                    $("#auction_unitIncrease").val(apiResult.data.unitIncrease);
                    $("#auction_startingPrice").val(apiResult.data.startingPrice);
                    $("#auction_securityDeposit").val(apiResult.data.securityDeposit);
                    $("#auction_delay").val(apiResult.data.delay ? '1' : '0');
                }, function () {
                }, "get");
            }, options);
        },
        del: function (id) {
            var self = this;
            hot.confirm('删除后将不可恢复，确定删除？', function () {
                hot.ajax("/product/normalDel", {
                    productId: id
                }, function (data) {
                    if (data.resultCode === 2000) {
                        layer.msg('删除成功');
                        self.reload();
                    } else {
                        layer.msg("失败：" + data.msg);
                    }
                }, function () {
                }, "post", 100);
            });
        },
        reload: function () {
            $('#searchForm').submit();
        }
    };
</script>
</body>
</html>
